package com.openbravo.data.gui;

import com.openbravo.data.loader.IKeyGetter;
import com.openbravo.data.loader.KeyGetterBuilder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

public class ComboBoxValModel extends AbstractListModel
  implements ComboBoxModel
{
  private List m_aData;
  private IKeyGetter m_keygetter;
  private Object m_selected;

  public ComboBoxValModel(List paramList, IKeyGetter paramIKeyGetter)
  {
    this.m_aData = paramList;
    this.m_keygetter = paramIKeyGetter;
    this.m_selected = null;
  }

  public ComboBoxValModel(List paramList)
  {
    this(paramList, KeyGetterBuilder.INSTANCE);
  }

  public ComboBoxValModel(IKeyGetter paramIKeyGetter)
  {
    this(new ArrayList(), paramIKeyGetter);
  }

  public ComboBoxValModel()
  {
    this(new ArrayList(), KeyGetterBuilder.INSTANCE);
  }

  public void add(Object paramObject)
  {
    this.m_aData.add(paramObject);
  }

  public void add(int paramInt, Object paramObject)
  {
    this.m_aData.add(paramInt, paramObject);
  }

  public void refresh(List paramList)
  {
    this.m_aData = paramList;
    this.m_selected = null;
  }

  public Object getSelectedKey()
  {
    if (this.m_selected == null)
      return null;
    return this.m_keygetter.getKey(this.m_selected);
  }

  public String getSelectedText()
  {
    if (this.m_selected == null)
      return null;
    return this.m_selected.toString();
  }

  public void setSelectedKey(Object paramObject)
  {
    setSelectedItem(getElementByKey(paramObject));
  }

  public void setSelectedFirst()
  {
    this.m_selected = (this.m_aData.size() == 0 ? null : this.m_aData.get(0));
  }

  public Object getElementByKey(Object paramObject)
  {
    if (paramObject != null)
    {
      Iterator localIterator = this.m_aData.iterator();
      while (localIterator.hasNext())
      {
        Object localObject = localIterator.next();
        if (paramObject.equals(this.m_keygetter.getKey(localObject)))
          return localObject;
      }
    }
    return null;
  }

  public Object getElementAt(int paramInt)
  {
    return this.m_aData.get(paramInt);
  }

  public Object getSelectedItem()
  {
    return this.m_selected;
  }

  public int getSize()
  {
    return this.m_aData.size();
  }

  public void setSelectedItem(Object paramObject)
  {
    if (((this.m_selected != null) && (!this.m_selected.equals(paramObject))) || ((this.m_selected == null) && (paramObject != null)))
    {
      this.m_selected = paramObject;
      fireContentsChanged(this, -1, -1);
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.gui.ComboBoxValModel
 * JD-Core Version:    0.6.0
 */